package com.szosen.measurement;

import android.R.integer;

public class Frame {

	public int	Length;			// 数据包长度		
	public int	HR;				// 心率
	public int	SaRate;			// 采样率
	public int	Paace;			// 起搏器信号标记
	public int	LeadStatus;		// 通道状态
	public int[]	ECG;			// 通道数据
	public int	Sum;
	public Frame(byte[] byteData){
		
		Length= ((byteData[1] << 8 & 0x0ff00) + (byteData[0] & 0xff));
		HR=((byteData[3] << 8 & 0x0ff00) + (byteData[2] & 0xff));
		SaRate=((byteData[5] << 8 & 0x0ff00) + (byteData[4] & 0xff));
		Paace=((byteData[7] << 8 & 0x0ff00) + (byteData[6] & 0xff));
		LeadStatus=((byteData[9] << 8 & 0x0ff00) + (byteData[8] & 0xff));
		ECG=new int[12];
		for(int i=0;i<8;i++){
			int tmp=((byteData[11+2*i] << 8& 0xff00) + (byteData[10+2*i]& 0xff));
			if((tmp&0x8000)==0x8000){
				ECG[i]=-((~(tmp|0xffff0000))+1);
			}else {
				ECG[i]=tmp;
			}
		}
		//ECG 0-7 分别对应的是 I, II, V1,V2,V3,V4,V5,V6
		//III		=	II - I
		//		aVR	=	(- II - I) / 2
		//				aVL	=	(- II - 2 * I1) / 2
		//				aVF	=	(2 * II - I) / 2
		ECG[8]=ECG[1]-ECG[0];//III
		ECG[9]=(-ECG[1]-ECG[0])/2;//aVR
		ECG[10]=(-ECG[1]-2*ECG[0])/2;//aVR
		ECG[11]=(2*ECG[1]-ECG[0])/2;//aVF	=	(2 * II - I) / 2
	}
}
